package com.silence.gmall.product.domain.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.repository.CrudRepository;
import com.silence.gmall.product.assembler.SpuImageFactory;
import com.silence.gmall.product.domain.entity.SpuImage;
import com.silence.gmall.product.domain.mapper.SpuImageMapper;
import com.silence.gmall.product.domain.repository.SpuImageRepository;
import com.silence.gmall.product.dto.SpuImageDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author silence
 * @Description 针对表【spu_image(商品图片表)】的数据库操作Repository实现
 * @Date 2025-08-17 16:28:16
 */
@Slf4j
@Repository
@RequiredArgsConstructor
public class SpuImageRepositoryImpl extends CrudRepository<SpuImageMapper, SpuImage>
    implements SpuImageRepository {

    /**
     * 商品图片工厂
     */
    private final SpuImageFactory spuImageFactory;

    /**
     * 根据spuId获取图片列表
     *
     * @param spuId spuId
     * @return 图片列表
     */
    @Override
    public List<SpuImageDto> getSpuImageList(Long spuId) {
        return spuImageFactory.spuImageList2SpuImageDtoList(list(new LambdaQueryWrapper<SpuImage>()
                .eq(SpuImage::getSpuId, spuId)));
    }
}